<template>
  <div class="app-container">
    <!-- 高级查询 -->
    <el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item label=":">
        <el-input v-model="queryParams.identical" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.front" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.left" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.right" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.bottom" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.engin" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.functional" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.threeLeakage" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.dashBoard" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.oilRefill" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.mileage" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.addGasConfirm" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.electrocityLevel" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.outLook" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.innerLook" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.outPartsLook" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.innerPartsLook" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.tirePleasure" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.volt" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.vehicleInfo" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.electInfo" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.oilCheck" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.assorryParts" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:pdiResult:insert']" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:pdiResult:update']" type="success" icon="el-icon-edit" size="mini" :disabled="isSingle" @click="handleEdit">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:pdiResult:delete']" type="danger" icon="el-icon-delete" size="mini" :disabled="isMultiple" @click="handleRemove">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:pdiResult:export']" type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
    </el-row>

    <!-- 数据列表 -->
    <el-table v-loading="loading" :data="page.records" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" />
      <el-table-column label="" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="" align="center" prop="identical" />
      <el-table-column label="" align="center" prop="front" />
      <el-table-column label="" align="center" prop="left" />
      <el-table-column label="" align="center" prop="right" />
      <el-table-column label="" align="center" prop="bottom" />
      <el-table-column label="" align="center" prop="engin" />
      <el-table-column label="" align="center" prop="functional" />
      <el-table-column label="" align="center" prop="threeLeakage" />
      <el-table-column label="" align="center" prop="dashBoard" />
      <el-table-column label="" align="center" prop="oilRefill" />
      <el-table-column label="" align="center" prop="mileage" />
      <el-table-column label="" align="center" prop="addGasConfirm" />
      <el-table-column label="" align="center" prop="electrocityLevel" />
      <el-table-column label="" align="center" prop="outLook" />
      <el-table-column label="" align="center" prop="innerLook" />
      <el-table-column label="" align="center" prop="outPartsLook" />
      <el-table-column label="" align="center" prop="innerPartsLook" />
      <el-table-column label="" align="center" prop="tirePleasure" />
      <el-table-column label="" align="center" prop="volt" />
      <el-table-column label="" align="center" prop="vehicleInfo" />
      <el-table-column label="" align="center" prop="electInfo" />
      <el-table-column label="" align="center" prop="oilCheck" />
      <el-table-column label="" align="center" prop="assorryParts" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermission="['web:pdiResult:update']" size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
          <el-button v-hasPermission="['web:pdiResult:delete']" size="mini" type="text" icon="el-icon-delete" @click="handleRemove(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize" @pagination="handleQuery" />

    <!-- 添加/修改对话框 -->
    <el-dialog :title="pdiResultFormDialog.title" :visible.sync="pdiResultFormDialog.visible" :close-on-click-modal="false" :before-close="resetPdiResultFormDialog" width="500px" append-to-body>
      <el-form ref="pdiResultForm" :model="pdiResultFormData" :rules="pdiResultFormRules" label-width="80px">
        <el-form-item label="" prop="identical">
          <el-input v-model="pdiResultFormData.identical" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="front">
          <el-input v-model="pdiResultFormData.front" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="left">
          <el-input v-model="pdiResultFormData.left" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="right">
          <el-input v-model="pdiResultFormData.right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="bottom">
          <el-input v-model="pdiResultFormData.bottom" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="engin">
          <el-input v-model="pdiResultFormData.engin" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="functional">
          <el-input v-model="pdiResultFormData.functional" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="threeLeakage">
          <el-input v-model="pdiResultFormData.threeLeakage" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="dashBoard">
          <el-input v-model="pdiResultFormData.dashBoard" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="oilRefill">
          <el-input v-model="pdiResultFormData.oilRefill" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="mileage">
          <el-input v-model="pdiResultFormData.mileage" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="addGasConfirm">
          <el-input v-model="pdiResultFormData.addGasConfirm" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="electrocityLevel">
          <el-input v-model="pdiResultFormData.electrocityLevel" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="outLook">
          <el-input v-model="pdiResultFormData.outLook" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="innerLook">
          <el-input v-model="pdiResultFormData.innerLook" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="outPartsLook">
          <el-input v-model="pdiResultFormData.outPartsLook" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="innerPartsLook">
          <el-input v-model="pdiResultFormData.innerPartsLook" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="tirePleasure">
          <el-input v-model="pdiResultFormData.tirePleasure" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="volt">
          <el-input v-model="pdiResultFormData.volt" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="vehicleInfo">
          <el-input v-model="pdiResultFormData.vehicleInfo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="electInfo">
          <el-input v-model="pdiResultFormData.electInfo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="oilCheck">
          <el-input v-model="pdiResultFormData.oilCheck" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="assorryParts">
          <el-input v-model="pdiResultFormData.assorryParts" placeholder="请输入" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmPdiResultFormDialog">确 定</el-button>
        <el-button @click="resetPdiResultFormDialog">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import PdiResultApi from '@/api/web/PdiResultApi'

const defaultPdiResultFormData = {
  identical: null,  front: null,  left: null,  right: null,  bottom: null,  engin: null,  functional: null,  threeLeakage: null,  dashBoard: null,  oilRefill: null,  mileage: null,  addGasConfirm: null,  electrocityLevel: null,  outLook: null,  innerLook: null,  outPartsLook: null,  innerPartsLook: null,  tirePleasure: null,  volt: null,  vehicleInfo: null,  electInfo: null,  oilCheck: null,  assorryParts: null}
export default {
  name: 'PdiResultList',
  data() {
    return {
      options: {
        sysYnTypeOptions: this.$constant.sysYnTypeOptions
      },
      queryParams: {
        identical: null,
        front: null,
        left: null,
        right: null,
        bottom: null,
        engin: null,
        functional: null,
        threeLeakage: null,
        dashBoard: null,
        oilRefill: null,
        mileage: null,
        addGasConfirm: null,
        electrocityLevel: null,
        outLook: null,
        innerLook: null,
        outPartsLook: null,
        innerPartsLook: null,
        tirePleasure: null,
        volt: null,
        vehicleInfo: null,
        electInfo: null,
        oilCheck: null,
        assorryParts: null,
        isValid: this.$constant.Y
      },
      page: {
        current: 1,
        pageSize: 10,
        total: 0,
        records: []
      },
      pdiResultFormDialog: {
        title: '',
        visible: false
      },
      pdiResultFormData: Object.assign({}, defaultPdiResultFormData),
      pdiResultFormRules: {
      },
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.handleQuery()
    this.loadOptions()
  },
  methods: {
    loadOptions() {
    },
    handleAdd() {
      this.openPdiResultFormDialog()
    },
    handleRemove(row) {
      const ids = row.id || this.multipleSelection.map(item => item.id)
      this.$confirm('是否确认删除数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return PdiResultApi.remove(ids)
      }).then(() => {
        this.handleQuery()
        this.$message.success('删除成功')
      })
    },
    handleEdit(row) {
      const id = row.id || this.multipleSelection.map(item => item.id)[0]
      this.openPdiResultFormDialog(id)
    },
    handleQuery() {
      this.loading = true
      PdiResultApi.page(this.queryParams, this.page).then(response => {
        this.page.records = response.data.records
        this.page.total = response.data.total
        this.loading = false
      }, () => {
        this.loading = false
      })
    },
    handleExport() {
      this.$confirm('是否确认导出数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return PdiResultApi.exportData(this.queryParams)
      }).then(response => {
        this.$common.download(response.msg)
      })
    },
    openPdiResultFormDialog(id) {
      this.pdiResultFormDialog.visible = true
      if (id) {
        this.pdiResultFormDialog.title = 'PDI检查-修改'
        PdiResultApi.get(id).then(response => {
          this.pdiResultFormData = {
            ...this.pdiResultFormData,
            ...response.data
          }
        })
      } else {
        this.pdiResultFormDialog.title = 'PDI检查-添加'
      }
    },
    confirmPdiResultFormDialog() {
      this.$refs['pdiResultForm'].validate(valid => {
        if (valid) {
          if (this.pdiResultFormData.id) {
            PdiResultApi.edit(this.pdiResultFormData).then(response => {
              this.$message.success('修改成功')
              this.resetPdiResultFormDialog()
              this.handleQuery()
            })
          } else {
            PdiResultApi.add(this.pdiResultFormData).then(response => {
              this.$message.success('添加成功')
              this.resetPdiResultFormDialog()
              this.handleQuery()
            })
          }
        }
      })
    },
    resetPdiResultFormDialog() {
      this.pdiResultFormDialog = {
        title: '',
        visible: false
      }
      this.pdiResultFormData = Object.assign({}, defaultPdiResultFormData)
      this.resetForm('pdiResultForm')
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.isSingle = selection.length !== 1
      this.isMultiple = !selection.length
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
